var prefix = "/reply";
//点击回复
$('.allreseponse').click(function () {
    // $('.huifu').attr('style','padding: 20px;');
    var it=$(this).parent().siblings('.huifu');
    it.attr('style','padding: 20px;');
    it.children().attr('style','margin-top: 0px;');
})

//点击取消
$('.giveup').click(function () {
    $(this).parents('.allhuifu').attr('style','height: 0;');
    $(this).parents('.huifu').removeAttr('style');
})

//添加评论
function commentadd() {
    var content = $('#comment_input').val();
    var matterId = $('#matter-name').val();

    $.ajax({
        url: '/comment/cadd',
        type: 'POST',
        dataType: 'JSON',
        data: {
            content: content,
            matterId: matterId,
        },
        success: function (rs) {
           // alert("评论成功");

            window.location.reload();
        },
        error: function (rs) {
           // alert("评论失败");
            window.location.reload();
        }
    })

}

/**
 * 删除评论
 */
function cdel(id) {
    alert(id);
    $.ajax({
        url: '/comment/cdelete',
        type: 'post',
        dataType: 'JSON',
        data: {
            id: id,
        },
        success: function (data) {

            if(data == "0"){
              //  alert("删除成功！");
            }else{
              //  alert("删除失败！");
            }
            window.location.reload();

        }
    })

}

function replyadd(id) {
    var replycontent = $('#reply-content').val();
    $.ajax({
        cache : true,
        url: '/reply/radd',
        type: 'POST',
        data: {
            replycontent: replycontent,
            commentId: id,
        },
        async : false,
        dataType: 'JSON',
        success : function(r) {
            if (r.code == 0) {
                //  alert("ok");
                //   parent.layer.msg(r.msg);
                //   parent.reLoad();
                parent.location.reload();//父页面
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                  parent.layer.close(index);

            } else {
                // alert("error");
                parent.location.reload();
                // parent.layer.msg(r.msg);
            }

        }
    })


}

function r(id) {

    layer.open ({
        type : 2,
        title : '请输入你的回复内容',
        elem: '#test1', //指定元素
        maxmin : true,
        shadeClose : true, // 点击遮罩关闭层
        area : [ '500px', '480px' ],
        content : prefix + '/reply/' + id // iframe的url
    });
}


